<template>
  <div id="CommercialTenant">

    <el-form>

      <br>
      <el-form-item label="商户名称">
        <el-input v-model="searchObj.merchantName"></el-input>
      </el-form-item>
      <br>
      <br>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column
          label="id"
          width="180"
          prop="id">
        <template slot-scope="scope">
          <router-link :to="{path:'/commercialTenantById',query:{index:scope.row.id}}">
            {{scope.row.id}}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column
          label="商户名"
          width="180" prop="merchantName">
      </el-table-column>
      <el-table-column
          prop="idCard"
          label="身份证号码"
          width="300">
      </el-table-column>
      <el-table-column
          prop="license_url"
          label="营业执照图片"
          width="300">

        <template slot-scope="scope">
          <img :src="scope.row.merchantImage" width="30%">
        </template>
      </el-table-column>
      <el-table-column
          label="门店地址"
          prop="merchantAddr"
          width="500">
      </el-table-column>
      <el-table-column
          label="联系方式"
          prop="merchantNumber"
          width="180">
      </el-table-column>
      <el-table-column
          label="是否营业"
          prop="onOff"
          width="180">
        <template slot-scope="scope">
          {{ scope.row.onOff === 1 ? '营业' : '歇业' }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="warning" @click="showAddDialog(scope.$index, scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- //分页功能 -->
    <div class="block">

      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNo"
          :page-sizes="pageSizeList"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

    <!--添加对话框-->
    <el-dialog title="商户审核" :visible.sync="addFormVisible" width="60%">
      <el-form :inline="true" :model="addForm" class="demo-from-inline" >
        <input type="hidden" name="id" :value="addForm.id"></input>
        <br/>
        <el-form-item label="商户名">
          <el-input v-model="addForm.merchantName" autocomplete="off" readonly></el-input>
        </el-form-item>
        <br/>
        <el-form-item label="身份证号码">
          <el-input v-model="addForm.idCard" autocomplete="off" readonly></el-input>
        </el-form-item>
        <br/>
        <el-form-item label="营业执照图片" prop="licenseUrl">
          <img :src="addForm.merchantImage" width="30%">
        </el-form-item>
        <br/>
        <el-form-item label="审核意见">
          <el-input v-model="addForm.auditOpinion" autocomplete="off" ></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input type="text" :value="addForm.merchantAddr" ></el-input>
        </el-form-item>
        <br/>
        <el-form-item label="审核人">
          <el-input type="text" :value="addForm.checker"></el-input>
        </el-form-item>
        <br/>
      </el-form>
      <div slot="footer">
        <el-button @click="addFormVisible = false">取 消</el-button>
        <el-button type="success" @click="not">不 通 过</el-button>
        <el-button type="primary" @click="uptsainv">通 过</el-button>
      </div>


    </el-dialog>


  </div>
</template>

<script>
export default {
  created() {
    this.getComments()
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val
      this.getComments()
    },
    async not(){
      const data = await this.$http.post
      (`/merchant/updateNot`,this.addForm)
      if(data.status==200){
        this.addFormVisible = false
        this.$message('审核不通过')
        this.getComments()
      }
    },
    async uptsainv(){

      const data = await this.$http.post
      (`/merchant/updateOk`,this.addForm)
      if(data.status == 200){
        // 隐藏
        this.addFormVisible = false
        // 消息提示
        this.$message('审核通过')
        // 刷新表格
        this.getComments()
      }
    },
    handleCurrentChange(val) {
      this.pageNo = val
      this.getComments()
    },
    search(){
      this.pageNo=1,
          this.getComments()
    },
    async getComments(){
      const {data : res} = await this.$http.post(`/merchant/selAduit/${this.pageNo}/${this.pageSize}`,this.searchObj)
      this.tableData = res.rows
      this.total = res.total
    },
    showAddDialog(index, row) {
      this.addFormVisible = true

      this.addForm = row

    }
  },

  data() {
    return {
      tableData: [

      ],// 添加对话框的显示
      addFormVisible: false,
      pageNo:1,
      pageSizeList:[2,5,10,20],
      total:0,
      pageSize:2,
      searchObj: {

      },
      addForm:{

      }
    }
  }
}
</script>

<style scoped>

</style>